package com.tzxx.spider.controller;

import com.tzxx.spider.domain.Article;
import com.tzxx.spider.service.ArticleService;
import com.tzxx.spider.vo.PageVo;
import com.tzxx.spider.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Created by tzxx
 * @since : 2019/5/16.
 */
@RestController
public class ApiController {


    @Resource
    private ArticleService articleService;

    @GetMapping("/articles")
    public Result getAllArticle(@ModelAttribute PageVo pageVo) {
        Result<List<Article>> result = new Result<>();
        List<Article> articleList = articleService.getAllArticle(pageVo);
        result.setData(articleList);
        return result;
    }

    @GetMapping("/article/{id}")
    public Result getArticleById(@PathVariable long id) {
        Result<Article> result = new Result<>();
        Article article = articleService.getArticleById(id);
        result.setData(article);
        return result;
    }


}
